home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $VER: format.ped 2.0 (5.3.95) written by Robert Brandner
- **
- ** This macro formats the current paragraph 'flush-left'
- ** (from the current line to the next empty line).
- ** It also handles long words and end of file correctly.
- */
-
- OPTIONS RESULTS
-
- OPTIONS FAILAT 11 /* ignore warnings */
- SIGNAL ON SYNTAX /* ensure clean exit */
- SIGNAL ON FAILURE
- SIGNAL ON BREAK_C /* no label->syntax->exit */
-
- if (LEFT(ADDRESS(), 6) ~= "POLYED") then do
- if SHOW("Ports", "POLYED.1") then
- address 'POLYED.1'
- else do
- say "PolyEd is not running!"
- exit
- end
- end
-
- 'LOCKGUI'
-
- /*----- begin of custom code area --------------------------------------*/
-
- 'GETATTR' APPLICATION STEM APP. /* get all infos on app. */
- 'GETATTR' PROJECT APP.CURRENTPROJECT STEM PROJ. /* get infos on project */
- 'GETCURSORPOS' STEM CP. /* current line */
-
- /* now we get all lines until we reach an empty one or the end of the
- ** text, and join them in a buffer (with a space in between).
- ** While doing that, we mark all the lines we put into the buffer.
- */
- BUFFER = ""
- LINECOUNTER = CP.LINE
- 'POSITION SOL'
- 'BLOCK START'
- do forever
- 'GETLINE' VAR 'LINE' /* get line */
- LINE = strip(LINE, B, " "||'09'X) /* strip spaces and tabs */
- if length(LINE) = 0 then leave
- BUFFER = BUFFER||" "||LINE /* add to buffer */
- 'CURSOR DOWN' /* move to next line */
- LINECOUNTER = LINECOUNTER+1 /* increment linecounter */
- if LINECOUNTER > PROJ.LINES then do /* leave on end of text */
- 'POSITION EOL' /* mark last line too */
- leave
- end
- end
- 'ERASE' /* erase the marked area */
-
- /* Now we write out the buffer again. We could make
- ** different formats like flush left, flush right, block...
- ** To be faster we create a complete line internally
- ** instead of writing each single word.
- */
- line = ""
- len = 0
- numwords = words(BUFFER) /* #words in buffer */
- do i=1 to numwords
- w = word(BUFFER,i)
- wlen = length(w)
- if len = 0 then do /* a new line? */
- line=w
- len=wlen
- iterate i /* next word */
- end
- if len+wlen >= APP.VAR_RIGHTBORDER then do
- 'TEXT' line
- 'TEXT NEWLINE'
- line = ""
- len = 0
- end
- line = line||' '||w
- len = len+wlen+1 /* +1 for trailing space */
- end
-
- if len > 0 then do /* is there a rest? */
- 'TEXT' line /* then write it too. */
- 'TEXT NEWLINE'
- end
-
- /*----- end of custom code area ----------------------------------------*/
-
- 'UNLOCKGUI' /* Clean exit */
- EXIT
-
- SYNTAX: /* ARexx error... */
- say "Error line" SIGL ":" ERRORTEXT(RC) /* report it... */
- 'UNLOCKGUI' /* Unlock GUI! */
- EXIT /* exit */
-
- FAILURE:
- 'UNLOCKGUI' /* Unlock GUI! */
- EXIT /* exit */
-